using System;
using CommunityToolkit.Mvvm.Input;

namespace SchoolApp_Material.ViewModels;

public class FormViewModel : ViewModelBase
{
    public Action<FormViewModel> EditAction;
    public Action<FormViewModel> DelAction;

    #region 属性

    private int _id;

    public int Id
    {
        get => _id;
        set => SetProperty(ref _id, value);
    }

    private string _year;

    public string Year
    {
        get => _year;
        set => SetProperty(ref _year, value);
    }

    private string _code;

    public string Code
    {
        get => _code;
        set => SetProperty(ref _code, value);
    }

    private string _teacherCode;

    public string TeacherCode
    {
        get => _teacherCode;
        set => SetProperty(ref _teacherCode, value);
    }

    private string _teacherName;

    public string TeacherName
    {
        get => _teacherName;
        set => SetProperty(ref _teacherName, value);
    }

    private string _createOperatorCode;

    public string CreateOperatorCode
    {
        get => _createOperatorCode;
        set => SetProperty(ref _createOperatorCode, value);
    }

    private string _createOperatorName;

    public string CreateOperatorName
    {
        get => _createOperatorName;
        set => SetProperty(ref _createOperatorName, value);
    }

    private DateTime _createTime;

    public DateTime CreateTime
    {
        get => _createTime;
        set => SetProperty(ref _createTime, value);
    }

    private bool _canEdit = true;

    public bool CanEdit
    {
        get => _canEdit;
        set => SetProperty(ref _canEdit, value);
    }

    private bool _canDel = true;

    public bool CanDel
    {
        get => _canDel;
        set => SetProperty(ref _canDel, value);
    }

    #endregion

    #region 命令

    #region 编辑

    private RelayCommand _editCmd;

    public RelayCommand EditCmd =>
        _editCmd ??= new RelayCommand(ExecuteEditCmd,()=>CanEdit);

    private void ExecuteEditCmd()
    {
        EditAction?.Invoke(this);
    }

    #endregion

    #region 删除

    private RelayCommand _delCmd;

    public RelayCommand DelCmd =>
        _delCmd ??= new RelayCommand(ExecuteDelCmd,()=>CanDel);

    private void ExecuteDelCmd()
    {
        DelAction.Invoke(this);
    }

    #endregion

    #endregion
}